<template>
  <div>
    <div id="box">测试下载pdf</div>

    <button @click="download">点击下载</button>
  </div>
</template>

<script>
import html2canvas from 'html2canvas'
import JsPDF from 'jspdf'

export default {
  methods: {
    download() {
      html2canvas(document.getElementById('box'))
        .then((canvas) => {
          var pdf = new JsPDF()
          pdf.addImage(canvas, 'PDF', 0, 0);
          console.log('%c [ pdf ]', 'font-size:13px; background:pink; color:#bf2c9f;', pdf)
          pdf.save("download.pdf");
        })
    }
  }
}
</script>

<style>

</style>